package com.jxb.three;

/**
 * 盛最多水的容器
 */
public class MostWater_11 {

    public static void main(String[] args) {
        int[] height = {1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(height));
    }

    public static int maxArea(int[] height) {
        int i = 0;
        int j = height.length - 1;
        int maxWater = 0;
        while (i<j) {
            maxWater = height[i] < height[j] ?
                    Math.max(maxWater,(j-i)*height[i++]) :
                    Math.max(maxWater,(j-i)*height[j--]);
        }
        return maxWater;
    }

}
